<?php

namespace App\Admin\Controllers;

use App\Models\Service;
use App\Models\Module;
use App\Models\Country;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;


class ServiceController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('服务管理');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('服务管理');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('服务管理');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Service::class, function (Grid $grid) {

//            $grid->model()->ordered();
            $grid->disableFilter();
            $grid->disableExport();

            $grid->id('ID');
//            $grid->order('排序')->editable();
            $grid->title('标题')->editable();
            $grid->picture('头图')->image();
            $grid->link_to('链接至')->editable();
            $grid->updated_at('更新时间');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Service::class, function (Form $form) {

            $form->display('id', 'ID');
//            $form->number('order', '排序');
            $form->text('title', '标题');
            $form->url('link_to', '链接至');
            $form->image('picture', '头图')->removable();

            $form->display('created_at', '创建时间');
            $form->display('updated_at', '更新时间');

        });
    }

}
